<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<jsp:include page="/includes/top.jsp"></jsp:include>
<div class="page-header">
	<h1></h1>
</div>
<!-- /.page-header -->

<div class="row">
	<div class="col-xs-12">
		<div class="table-responsive">
			<table id="grid-table"
				class="table table-striped table-bordered table-hover">
				<thead>
					<tr>
						<th style="width:15px"><input type="checkbox" id="checkAll" class="ace"><span class="lbl"></span></th>
						<th>模块名称</th>
						<th>模块编码</th>
						<th>链接路径</th>
						<th>样式名称</th>
						<th>功能描述</th>
					</tr>
				</thead>
			</table>
		</div>
	</div>
</div>

<jsp:include page="/includes/bottom.jsp"></jsp:include>

<script type="text/javascript">
	var columns = [ {	
						"data" : "moduleId",
						"fnCreatedCell" : function (nTd, sData, oData, iRow, iCol) {
	                    	$(nTd).html("<input type='checkbox' name='checkList' value='" + sData + "' class='ace'><span class='lbl'></span>");
	                	}
	                }, 
					{"data" : "moduleName"}, 
					{"data" : "moduleCode"}, 
					{"data" : "modulePath"}, 
					{"data" : "moduleClass"}, 
					{"data" : "moduleDescription"} ];
					
	$(document).ready(function() {
		//参数说明：id,url,data,column,length			
		tableload("grid-table","modulegrid",null,columns,15);
		//checkbox全选
	    $("#checkAll").on("click", function () {
	        if ($(this).prop("checked")) {
	            $("input[name='checkList']").prop("checked", true);
	        } else {
	            $("input[name='checkList']").prop("checked", false);
	        }
	    });
	});
	
	function getSelected(){
		var str = '';
	    $("input[name='checkList']:checked").each(function () {
	        str += $(this).val();
	        str += ",";
	    });
	    str = str.substr(0, str.length - 1);
	    return str;
	}
	function _addFun(){
		window.open("admin/moduleform.jsp?m="+mid,"_self");
	}
	function _editFun(){
		var str = getSelected();
		if (str != '' && str.indexOf(",") < 0) {
			window.open("admin/moduleform.jsp?m=" + mid + "&id=" + str, "_self");
		} else {
			alert("请选择一条记录操作");
		}
	}
	function _delFun(){
	    var str = getSelected();
		if (str != '' && str.indexOf(",") < 0) {
			if (confirm("确定要删除数据吗？")) {
				$.ajax({
				type : "post",
				url : "delmodule",
				data : {'modules.moduleId':str},				
				success : function(data) {
					showDelMessage(data);
					window.open("admin/modulelist.jsp?m="+mid,"_self");
				}
			});
			}
		} else {
			alert("请选择一条记录操作");
		}
	}
</script>